<?php
/*
 * @Author: 李明
 * @Date: 2021-11-08 16:08:05
 * @LastEditTime: 2022-01-18 11:42:15
 * @LastEditors: 李明
 * @Description: 新订单接口
 * @FilePath: /CRM2.0-PHP/app/Http/Resources/OrderV2.php
 * @山东壹零贰肆信息科技有限公司
 */

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class OrderV2 extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $order = parent::toArray($request);
        $order['valid_time'] = date('Y-m-d', strtotime($this->valid_time));
        $order['sign_time'] = date('Y-m-d', strtotime($this->sign_time));
        $order['account_time'] = date('Y-m-d', strtotime($this->account_time));
        $order['contract_end_date'] =  date('Y-m-d', strtotime($this->contract_end_date));
        $pay_time_unit = $this->product->pay_time_unit ?? '';
        $pay_long =  $this->product->pay_long ?? '';
        switch ($this->pay_type) { // 付款方式付款方式  2自然月  4到期 5不付款 4自定义
            case '5':
                $order['product_pay_time'] = '无需支付';
                break;
            default:
                switch ($pay_time_unit) { // 付款间隔 1日、 2月、3年
                    case '1':
                        $order['product']['product_pay_time'] = $pay_long . '日/次';
                        break;
                    case '2':
                        $order['product']['product_pay_time'] = $pay_long . '月/次';
                        break;
                    case '3':
                        $order['product']['product_pay_time'] = $pay_long . '年/次';
                        break;
                    default:
                        $order['product']['product_pay_time'] = '';
                        break;
                }
        }
        // 判断通联认证状态
        $pay_status = '';
        switch ($this->investment_way) { // 投资状态  1常规 2通联未付款 3通联已付款
            case 1:
                $pay_status = '常规';
                break;
            case 2:
                $pay_status = '未付款';
                break;
            case 3:
                $pay_status = '已付款';
                break;
            default:
                $pay_status = '未知';
                break;
        }
        $order['pay_status'] = $pay_status;
        $order['product_name'] = $this->product->name;
        $order['bank_sum_name'] = $this->bank_card->bank_sum_name ?? '';
        $order['bank_num'] = $this->bank_card->bank_num ?? '';
        return $order;
    }
}
